package io.renren.controller;

import io.renren.common.entity.XlsShopOrdersEntity;
import io.renren.service.XlsShopOrdersService;
import io.renren.utils.AppResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * 线上订单表
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2020-04-12
 */
@RestController
@RequestMapping("/api/xlsshoporders")
@Api(tags="线上订单表")
public class XlsShopOrdersController {
    @Autowired
    private XlsShopOrdersService xlsShopOrdersService;

    /**
     * 提交线上订单
     * @param userId 用户id
     * @param userAddressId 地址id
     * @return
     */
    @PostMapping( "/addOrders")
    @ApiOperation("提交线上订单")
    public AppResult addOrders(Long userId,String paramStr, Long userAddressId, Integer type){
        return xlsShopOrdersService.addOrders(userId,paramStr,userAddressId,type);
    }

    /**
     * 订单列表
     * @param pageNum
     * @param userId
     * @param orderStatus
     * @return
     */
    @PostMapping( "/getAllOrderData")
    @ApiOperation("订单列表")
    public AppResult getAllOrderData(Integer pageNum,Long userId,String  orderStatus){
        return xlsShopOrdersService.getAllOrderData(pageNum,userId,orderStatus);
    }


    /**
     * 修改订单状态
     *
     * @return
     */
    @GetMapping("/updateOrderStatus")
    @ApiOperation("修改订单状态")
    public AppResult updateOrderStatus(XlsShopOrdersEntity shopOrders){
        return xlsShopOrdersService.updateOrderStatus(shopOrders);
    }




    /*********************************************************支付接口************************************************/
    /**
     *  第三方支付预下单
     * @param orderunique 流水号
     * @param payType 支付类型 1-微信 2-支付宝 3-快捷
     * @param bankCardId 银行卡id
     * @param userId 用户id
     * @return
     */
    @PostMapping("/thirdPayApply")
    @ApiOperation("第三方支付预下单")
    public AppResult thirdPayApply(HttpServletRequest request, String orderunique, String payType , String bankCardId, String userId){
        return  xlsShopOrdersService.thirdPayApply(request, orderunique, payType, bankCardId, userId);
    }

    /**
     * 支付宝支付回调
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @PostMapping("/aliPayBack")
    public  AppResult aliPayBack(HttpServletRequest request, HttpServletResponse response) throws IOException {
        return xlsShopOrdersService.aliPayBack(request,response);
    }

    /**
     * 微信支付回调
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @PostMapping("/wxPayBack")
    public  void wxPayBack(HttpServletRequest request, HttpServletResponse response){
        xlsShopOrdersService.wxPayBack(request,response);
    }

}